define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'school/index',
                    add_url: 'school/add',
                    edit_url: 'school/edit',
                    del_url: 'school/del',
                    multi_url: 'school/multi',
                    import_url: 'school/import',
                    table: 'school',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'province_text', title: __('address'),events: Controller.api.events.province,formatter: Controller.api.formatter.province},
                        // {field: 'city_text', title: __('City')},
                        // {field: 'area_text', title: __('Area')},
                        // {field: 'address', title: __('Address')},
                        {field: 'category', title: __('Category'), searchList: {"A":__('Category A'),"B":__('Category B'),"C":__('Category C'),"D":__('Category D'),"E":__('Category E')}, formatter: Table.api.formatter.normal},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'class', title: __('Class')},
                        {field: 'total_number', title: __('Total_number')},
                        {field: 'policylist', title: __('Policylist'), searchList: {"1":__('Policylist 1'),"2":__('Policylist 2'),"3":__('Policylist 3'),"4":__('Policylist 4')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'is_schoolsdata', title: __('Is_schoolsdata'), searchList: {"1":__('Is_schoolsdata 1'),"2":__('Is_schoolsdata 2')}, formatter: Table.api.formatter.normal},
                        {field: 'volume', title: __('Volume'), searchList: {"1":__('Volume 1'),"2":__('Volume 2'),"3":__('Volume 3'),"4":__('Volume 4'),"5":__('Volume 5')}, formatter: Table.api.formatter.normal},
                        {field: 'teaching_order', title: __('Teaching_order'), searchList: {"1":__('Teaching_order 1'),"2":__('Teaching_order 2'),"3":__('Teaching_order 3')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {//渲染的方法
                province: function (value, row, index) {
                    return '<a class="btn btn-xs btn-ip bg-success"> ' + value +','+row['city_text']+','+row['area_text']+','+row['address']+ '</a>';
                }
            },
            events: {//绑定事件的方法
                province: {
                    //格式为：方法名+空格+DOM元素
                    'click .btn-ip': function (e, value, row, index) {
                        e.stopPropagation();
                        Layer.alert("该行数据为: <code>" + JSON.stringify(row) + "</code>");
                    }
                }
            }

        }
    };
    return Controller;
});